package com.wangyadong.hobby.schedule.jobtask.mybatis;

import java.io.IOException;
import java.util.Scanner;

/**
 * <p>
 *
 * @author <714037465@qq.com>
 * @since 2018/8/29:36
 **/
public class DocumentEditThread extends Thread {
    private final String documentName;
    private final String documentPath;
    private final Scanner scanner = new Scanner(System.in);

    public DocumentEditThread(String documentPath, String documentName) {
        this.documentName = documentName;
        this.documentPath = documentPath;
    }

    @Override
    public void run() {
        try {
            Document document = new Document(documentPath, documentName);
            int times = 0;
            while (true) {
                String next = scanner.next();
                if (next.equals("quit")) {
                    document.close();
                    break;
                }
                document.edit(next);
                if (times == 5) {
                    document.save();
                    times = 0;
                }
                times++;
            }
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
}
